<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>制定生产派工单</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="/css/animate.css" rel="stylesheet">
    <link href="/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="/bootstraptable/bootstrap-table.css" rel="stylesheet">
</head>
<body>
<div style="color: #0e9aef;">您正在做的业务是：生产管理--生产调度管理--制定生产派工单</div>
<div style="margin-top: 10px">当前等待派工的生产计划总数：<span id="create_dispatch_ticket_total_span"></span>例
    <button type="button" class="btn btn-default col-md-offset-10" id="make_dispatch_ticket">生成派工单</button></div>


<div class="container" style="margin-top: 20px;">
    <form class="form-horizontal" id="create_dispatch_ticket_form">
        <div class="form-group">
            <div class="col-md-5">
                <label class="col-md-4 control-label">请输入产品编号：</label>
                <div class="col-md-8">
                    <input type="text" name="search_id" id="search_id" class="form-control" />
                </div>
            </div>
            <div class="col-md-5">
                <label class="col-md-4 control-label">请输入产品名称：</label>
                <div class="col-md-8">
                    <input type="text" name="search_name" id="search_name" class="form-control" />
                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="col-md-5">
                <label class="col-md-4 control-label">请输入审核时间：</label>
                <div class="col-md-4">
                    <input type="date" name="search_time1" id="search_time1" class="form-control">
                </div>
                <div class="col-md-4">
                    <input type="date" name="search_time2" id="search_time2" class="form-control">
                </div>
            </div>
            <div class="col-md-7">
                <input type="button" class="btn btn-default col-md-offset-7" value="查询" id="query_btn" />
            </div>
        </div>
    </form>
</div>

<!--查询未制定派工单的生产计划表-->
<table id="create_dispatch_ticket_table" style="margin-top: 20px"></table>



<!-- 全局js -->
<script src="/js/jquery.min.js?v=2.1.4"></script>
<script src="/js/bootstrap.min.js?v=3.3.6"></script>
<script src="/js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="/js/plugins/layer/layer.min.js"></script>

<!-- 自定义js -->
<script src="/js/hAdmin.js?v=4.1.0"></script>
<script src="/js/currentTime.js"></script>

<!-- 第三方插件 -->
<script src="/js/plugins/pace/pace.min.js"></script>

<!--BootstrapTable-->
<script src="/bootstraptable/bootstrap-table.min.js"></script>
<script src="/bootstraptable/locale/bootstrap-table-zh-CN.min.js"></script>

<script>
    $(function (){
        setTimeout(function (){
            let num=$("#create_dispatch_ticket_table").bootstrapTable("getOptions").totalRows
            $("#create_dispatch_ticket_total_span").html(num)
        },500)

        $("#create_dispatch_ticket_table").bootstrapTable({
            method: "post",
            contentType: "application/x-www-form-urlencoded",
            url: "/manufacture/apply/unMakeSendWorkOrder",
            // 数据行交替样式
            striped: true,
            // 是否是服务器端分页：server表示服务器端，client表示前端分页
            sidePagination: 'server',
            //初始化加载第一页
            pageNumber: 1,
            //是否分页
            pagination: true,
            // 单页记录数，页大小
            pageSize: 5,
            // 分页列表
            pageList: [8, 10, 20],
            //刷新按钮
            // showRefresh:true,
            // 请求参数
            queryParams: function (params) {
                let obj = {
                    // params.limit获取组件中的页大小
                    // params.offset获取请求数据的起始索引
                    pageSize: params.limit,
                    pageNo: (params.offset / params.limit) + 1,

                    search_id:$("#create_dispatch_ticket_form #search_id").val(),
                    search_name:$("#create_dispatch_ticket_form #search_name").val(),
                    search_time1:$("#create_dispatch_ticket_form #search_time1").val(),
                    search_time2:$("#create_dispatch_ticket_form #search_time2").val(),
                }
                return obj;
            },
            // 表格列标题
            columns: [{
                title: "点选",
                field: "id",
                formatter:function (value,row,index) {
                    return "<input type='checkbox' name='tap' value='"+row.id+"'>"
                }
            },{
                title: "计划单编号",
                field: "applyId",
            }, {
                title: "产品编号",
                field: "productId",
                formatter:function (value,row,index){
                    return  `<a href="javascript:getById(${row.productId})">${row.productId}</a>`
                }
            }, {
                title: "产品名称",
                field: "productName",
            }, {
                title: "描述",
                field: "productDescribe",
            }, {
                title: "数量",
                field: "amount"
            }, {
                title: "审核时间",
                field: "checkTime",
                formatter: function (value, row, index) {
                   return formater(value)
                }
            }]
        })

        $("#create_dispatch_ticket_form #query_btn").click(function (){
            $("#create_dispatch_ticket_table").bootstrapTable("refresh")
        })

        //点击制定派工单
        $("#make_dispatch_ticket").click(function (){
            //定义一个数组
            let ary=[]
            let check_val=[]
            //获取选中的
            let check=$("#create_dispatch_ticket_table :checkbox[name='tap']:checked")
            //
            if(check.length==0){
                alert("您没有选择生产计划明细,请选择")
                return
            }
            for (let i=0;i<check.length;i++){
                let check_ary=$(check[i]).parent("td").parent().find(":eq(3)").html()
                let val=$(check[i]).val()
                check_val.push(val)
                ary.push(check_ary)
            }

            let flag=false;
            //  0005 0005 0001
            for (let i=0;i<ary.length;i++){
                if(ary.indexOf(ary[i])){
                    flag =true
                }
            }

            if(flag==false){
                localStorage.setItem("ary",JSON.stringify(check_val))
                window.location="preview_the_dispatch_ticketUI"
                console.log("相等")

            }
            if(flag==true){
                alert("请选择与产品编号一致的生产计划明细记录")
                return
            }
        })
    })

    function getById(pid){
        localStorage.setItem("pid",pid)
        window.location="manufacture_product_file_inquiryUI"
    }
</script>
</body>
</html>